const resBaseUrl = '/static/images/'

// 兼容ios，时间格式化
function formateIOS(time) {
	var myDate = new Date(time.replace(/-/g, '/'));
	return myDate;
}

function getQrQuery(query, target) {
  let index = query.indexOf(target);
  let res = query.slice(index).split("&");
  return res[0].split("=")[1];
}


// 跳转
function skip(url){
	uni.navigateTo({
		url
	})
}

/**
 * @description 校验是否登录
 */
function checkUser() {
	return new Promise(async (resolve, reject) => {
		let userInfo = uni.getStorageSync('userInfo');
		if (userInfo) {
			resolve(JSON.parse(userInfo))
		} else {
			let pages = getCurrentPages()
			// console.log(pages)
			let forward = pages && pages[pages.length - 1] ? pages[pages.length - 1]['__page__'] : null
			uni.setStorageSync('forward', JSON.stringify(forward));
			uni.$u.route({
				type: 'redirect',
				url: '/pages/login/index'
			});
			reject(false)
		}
	})
}

module.exports = {
	checkUser,
	getQrQuery,
	resBaseUrl,
	formateIOS,
	skip
}
